//
//  HMLearnTimeController.m
//  HowToDo
//
//  Created by 李贺 on 2017/1/8.
//  Copyright © 2017年 KY. All rights reserved.
//

#import "HMLearnTimeController.h"
#import "HMFirstCell.h"
#import "HMsecondCell.h"
#import "HMThiredCell.h"

@interface HMLearnTimeController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation HMLearnTimeController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self makeTableView];
    self.navigationItem.title = @"学习记录";
}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (void)makeTableView{
    UITableView * tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    
    [self.view addSubview:tableView];
    
    tableView.dataSource= self;
    tableView.delegate =self;
    
    tableView.sectionHeaderHeight = 5;
    tableView.sectionFooterHeight = 5;
    
    // 用class来注册cell
    [tableView registerClass:[HMFirstCell class] forCellReuseIdentifier:@"HMFirstCell_ID"];
    [tableView registerClass:[HMsecondCell class] forCellReuseIdentifier:@"HMsecondCell_ID"];
    [tableView registerClass:[HMThiredCell class] forCellReuseIdentifier:@"HMThiredCell_ID"];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.001;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}




- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0){
        HMFirstCell *firstCell = [tableView dequeueReusableCellWithIdentifier:@"HMFirstCell_ID"];
        firstCell.selectionStyle = UITableViewCellSelectionStyleNone;
        return firstCell;
    }
    if(indexPath.section == 1){
        HMsecondCell *secondCell = [tableView dequeueReusableCellWithIdentifier:@"HMsecondCell_ID"];
        secondCell.selectionStyle = UITableViewCellSelectionStyleNone;
        return secondCell;
    }
    HMThiredCell *thiredCell = [tableView dequeueReusableCellWithIdentifier:@"HMThiredCell_ID"];
    thiredCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return thiredCell;
}

///取消选中 -- 点击显示阅读记录
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if(indexPath.section == 2){
        UIStoryboard * TimelinesSB = [UIStoryboard storyboardWithName:@"Timelines" bundle:nil];
        UIViewController * HMTimelinesVC = [TimelinesSB instantiateInitialViewController];
        
        HMTimelinesVC = [TimelinesSB instantiateViewControllerWithIdentifier:@"VC"];
        [self presentViewController:HMTimelinesVC animated:YES completion:nil];

    }
}


///返回每一行的具体行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.section == 0){
        return 150;
    }
    if(indexPath.section == 1){
        return 300;
    }return 130;
}


@end
